from PyQt4 import QtGui
from PyQt4 import QtCore
from OpenGL import GL

class PageSetupWindow (QtGui.QWidget):
    """
        TODO
    """
    
    def __init__(self, mainwindow):
        """
            Constructor
        """
        super(QtGui.QWidget, self).__init__(None)
        self.setObjectName("PageSetup")
        self.resize(590, 330)
        self.setWindowTitle(QtGui.QApplication.translate( "PageSetup",
                  "Page Setup", None, QtGui.QApplication.UnicodeUTF8 ) ) 

        self.mainwindow = mainwindow

        self.widget = QtGui.QWidget(self)
        self.widget.setGeometry(QtCore.QRect(0, 0, 585, 325))
        self.hboxlayout = QtGui.QHBoxLayout(self.widget)

        self.canvas_widget = QtGui.QWidget(self.widget)
        self.canvas_widget.setGeometry(QtCore.QRect(5, 5, 280, 325))

        self.canvas_label = QtGui.QLabel("CANVAS REGION ", self.canvas_widget)
        self.canvas_label.setGeometry(QtCore.QRect(0, 0, 200, 25)) 

        self.left_label = QtGui.QLabel("Left: ", self.canvas_widget)
        self.left_label.setGeometry(QtCore.QRect(25, 30, 200, 25)) 

        self.left_lineedit = QtGui.QLineEdit(self.canvas_widget)
        self.left_lineedit.setGeometry(QtCore.QRect(175, 30, 100, 25))

        self.right_label = QtGui.QLabel("Right: ", self.canvas_widget)
        self.right_label.setGeometry(QtCore.QRect(25, 60, 200, 25)) 

        self.right_lineedit = QtGui.QLineEdit(self.canvas_widget)
        self.right_lineedit.setGeometry(QtCore.QRect(175, 60, 100, 25))

        self.top_label = QtGui.QLabel("Top: ", self.canvas_widget)
        self.top_label.setGeometry(QtCore.QRect(25, 90, 200, 25)) 

        self.top_lineedit = QtGui.QLineEdit(self.canvas_widget)
        self.top_lineedit.setGeometry(QtCore.QRect(175, 90, 100, 25))

        self.bottom_label = QtGui.QLabel("Bottom: ", self.canvas_widget)
        self.bottom_label.setGeometry(QtCore.QRect(25, 120, 200, 25)) 

        self.bottom_lineedit = QtGui.QLineEdit(self.canvas_widget)
        self.bottom_lineedit.setGeometry(QtCore.QRect(175, 120, 100, 25))

        self.background_color_button = QtGui.QPushButton(self.canvas_widget)
        self.background_color_button.setGeometry(QtCore.QRect(25, 150, 120, 25))
        self.background_color_button.setText("&Background Color")
 
        self.background_color_label = QtGui.QLabel(self.canvas_widget)
        self.background_color_label.setGeometry(QtCore.QRect(175, 150, 100, 25))
        self.background_color_label.setFrameShape(QtGui.QFrame.StyledPanel)
        self.background_color_label.setScaledContents(True)
        self.connect( self.background_color_button, QtCore.SIGNAL("clicked()"), 
                                              self.getBackgroundColor )
        self.setColor(self.mainwindow.backgroundColor, self.background_color_label)

        self.edge_color_button = QtGui.QPushButton(self.canvas_widget)
        self.edge_color_button.setGeometry(QtCore.QRect(25, 180, 120, 25))
        self.edge_color_button.setText("&Edge Color")
        self.connect(self.edge_color_button, QtCore.SIGNAL("clicked()"), self.getEdgesColor)
         
        self.edges_color_label = QtGui.QLabel(self.canvas_widget)
        self.edges_color_label.setGeometry(QtCore.QRect(175, 180, 100, 25))
        self.edges_color_label.setFrameShape(QtGui.QFrame.StyledPanel)
        self.edges_color_label.setScaledContents(True)
        self.setColor(self.mainwindow.edgesColor, self.edges_color_label)


        self.points_color_button = QtGui.QPushButton(self.canvas_widget)
        self.points_color_button.setGeometry(QtCore.QRect(25, 210, 120, 25))
        self.points_color_button.setText("&Points Color")
 
        self.points_color_label = QtGui.QLabel(self.canvas_widget)
        self.points_color_label.setGeometry(QtCore.QRect(175, 210, 100, 25))
        self.points_color_label.setFrameShape(QtGui.QFrame.StyledPanel)
        self.points_color_label.setScaledContents(True)
        self.connect( self.points_color_button, QtCore.SIGNAL("clicked()"), 
                                              self.getPointsColor )
        self.setColor(self.mainwindow.pointsColor, self.points_color_label)

        self.points_size_label = QtGui.QLabel("Points size",self.canvas_widget)
        self.points_size_label.setGeometry(QtCore.QRect(25, 240, 200, 25))

        self.point_size_spinbox = QtGui.QSpinBox(self.canvas_widget)
        self.point_size_spinbox.setGeometry(QtCore.QRect(175, 240, 100, 25))
        self.point_size_spinbox.setRange(1, 10)
        self.point_size_spinbox.setValue(5)
        self.point_size_spinbox.setToolTip("Size of the Points")
        self.point_size_spinbox.setFocusPolicy(QtCore.Qt.NoFocus)
        self.connect( self.point_size_spinbox, QtCore.SIGNAL("valueChanged(int)"), 
                                              self.setPointsSize )


        self.algorithm_widget = QtGui.QWidget(self.widget)
        self.algorithm_widget.setGeometry(QtCore.QRect(300, 5, 280, 320))


        self.algorithm_label = QtGui.QLabel("ALGORITHMS ", self.algorithm_widget)
        self.algorithm_label.setGeometry(QtCore.QRect(0, 0, 200, 25))  

        self.remove_int_points_label = QtGui.QLabel("Remove Interior Points: ", self.algorithm_widget)
        self.remove_int_points_label.setGeometry(QtCore.QRect(25, 30, 150, 25)) 

        self.remove_int_points_checkbox = QtGui.QCheckBox(self.algorithm_widget)
        self.remove_int_points_checkbox.setGeometry(QtCore.QRect(175, 30, 20, 20)) 
        
        
        self.sorting_label = QtGui.QLabel("Sorting: ", self.algorithm_widget)
        self.sorting_label.setGeometry(QtCore.QRect(25, 60, 200, 25)) 

        self.sorting_combobox = QtGui.QComboBox(self.algorithm_widget)
        self.sorting_combobox.setGeometry(QtCore.QRect(175, 60, 100, 25))
        self.sorting_combobox.addItem("Merge")
        self.sorting_combobox.addItem("Quick")
        self.sorting_combobox.setToolTip("Algorithm for sorting numbers")        

        self.output_info_label = QtGui.QLabel("OUTPUT INFO ", self.algorithm_widget)
        self.output_info_label.setGeometry(QtCore.QRect(0, 100, 200, 25))  

        self.convexhull_algorithm_label = QtGui.QLabel("Convex Hull: ", self.algorithm_widget)
        self.convexhull_algorithm_label.setGeometry(QtCore.QRect(25, 130, 150, 25)) 

        self.convexhull_algorithm_checkbox = QtGui.QCheckBox(self.algorithm_widget)
        self.convexhull_algorithm_checkbox.setGeometry(QtCore.QRect(175, 130, 20, 20)) 

        self.sorting_algorithm_label = QtGui.QLabel("Sorting:", self.algorithm_widget)
        self.sorting_algorithm_label.setGeometry(QtCore.QRect(25, 160, 150, 25)) 

        self.sorting_algorithm_checkbox = QtGui.QCheckBox(self.algorithm_widget)
        self.sorting_algorithm_checkbox.setGeometry(QtCore.QRect(175, 160, 20, 20)) 

        self.region_label = QtGui.QLabel("Region:", self.algorithm_widget)
        self.region_label.setGeometry(QtCore.QRect(25, 190, 150, 25)) 

        self.region_checkbox = QtGui.QCheckBox(self.algorithm_widget)
        self.region_checkbox.setGeometry(QtCore.QRect(175, 190, 20, 20)) 

        self.quantity_points_label = QtGui.QLabel("Quantity of Points:", self.algorithm_widget)
        self.quantity_points_label.setGeometry(QtCore.QRect(25, 220, 150, 25)) 

        self.quantity_points_checkbox = QtGui.QCheckBox(self.algorithm_widget)
        self.quantity_points_checkbox.setGeometry(QtCore.QRect(175, 220, 20, 20)) 

        self.time_label = QtGui.QLabel("Time:", self.algorithm_widget)
        self.time_label.setGeometry(QtCore.QRect(25, 250, 250, 25)) 

        self.time_checkbox = QtGui.QCheckBox(self.algorithm_widget)
        self.time_checkbox.setGeometry(QtCore.QRect(175, 250, 20, 20)) 

        self.buttons_widget = QtGui.QWidget(self.widget)
        self.buttons_widget.setGeometry(QtCore.QRect(5, 290, 585, 40))

        self.apply_buttom = QtGui.QPushButton("Apply", self.buttons_widget)
        self.apply_buttom.setGeometry(QtCore.QRect(225, 0, 100, 30))
        self.connect(self.apply_buttom, QtCore.SIGNAL("clicked()"), self.applyButtom)

        self.cancel_buttom = QtGui.QPushButton("Cancel", self.buttons_widget)
        self.cancel_buttom.setGeometry(QtCore.QRect(350, 0, 100, 30))
        self.connect(self.cancel_buttom, QtCore.SIGNAL("clicked()"), self.cancel)

        self.ok_buttom = QtGui.QPushButton("Ok", self.buttons_widget)
        self.ok_buttom.setGeometry(QtCore.QRect(475, 0, 100, 30))
        self.connect(self.ok_buttom, QtCore.SIGNAL("clicked()"), self.ok)


    def setColor(self, color, label):
        pixmap = self._makePixmap(color, 60, 30)
        label.setPixmap(pixmap) 
        
    def _makePixmap(self, color, width, height):
        pixmap = QtGui.QPixmap(width, height)
        brush = QtGui.QBrush(color, QtCore.Qt.BrushStyle(QtCore.Qt.SolidPattern))
        painter = QtGui.QPainter(pixmap)
        painter.fillRect(pixmap.rect(), brush)
        return pixmap     

    def getBackgroundColor(self):
        color = QtGui.QColorDialog.getColor(QtCore.Qt.black, self)
        if color.isValid():
            self.mainwindow.backgroundColor = color
        self.setColor(self.mainwindow.backgroundColor, self.background_color_label)          
        
    def getEdgesColor(self):
        color = QtGui.QColorDialog.getColor(QtCore.Qt.black, self)
        if color.isValid():
            self.mainwindow.edgesColor = color

        self.setColor(self.mainwindow.edgesColor, self.edges_color_label)                  
        
    def getPointsColor(self):
        color = QtGui.QColorDialog.getColor(QtCore.Qt.black, self)
        if color.isValid():
            self.mainwindow.pointsColor = color

        self.setColor(self.mainwindow.pointsColor, self.points_color_label)          

    def setPointsSize(self):
        self.mainwindow.pointsSize = self.point_size_spinbox.value()
        
    def applyButtom(self):
        self.mainwindow.glwidget.drawer.setPointsColor( 
                            float( self.mainwindow.pointsColor.red() ) / 255,
                            float( self.mainwindow.pointsColor.green() ) / 255, 
                            float( self.mainwindow.pointsColor.blue() ) / 255 )  

        self.mainwindow.glwidget.drawer.setEdgesColor( 
                                    float( self.mainwindow.edgesColor.red() ) / 255,
                                    float( self.mainwindow.edgesColor.green() ) / 255, 
                                    float( self.mainwindow.edgesColor.blue() ) / 255 )  

        self.mainwindow.glwidget.setBackgroundColor(
                                float( self.mainwindow.backgroundColor.red() ) / 255,
                                float( self.mainwindow.backgroundColor.green() ) / 255, 
                                float( self.mainwindow.backgroundColor.blue() ) / 255 )

        self.mainwindow.glwidget.drawer.setPointSize(self.mainwindow.pointsSize)

        self.mainwindow.glwidget.glDraw()     
    
    def cancel(self):
        self.close()
        
    def ok(self):
        self.applyButtom()
        self.close()


#################################################################
        
class ReportSetupWindow (QtGui.QWidget):
    """
        TODO
    """
    
    def __init__(self, parent=None):
        """
            Constructor
        """
        super(QtGui.QWidget, self).__init__(parent)
        self.setObjectName("ReportSetup")
        self.resize(560, 430)
        self.setWindowTitle(QtGui.QApplication.translate( "ReportSetup",
                  "Report Setup", None, QtGui.QApplication.UnicodeUTF8 ) ) 

        self.widget = QtGui.QWidget(self)
        self.widget.setGeometry(QtCore.QRect(0, 0, 795, 595))
        self.vboxlayout = QtGui.QVBoxLayout(self.widget)

        self.setup_widget = QtGui.QWidget(self.widget)
        self.setup_widget.setGeometry(QtCore.QRect(5, 5, 550, 550))

        self.iterations_label = QtGui.QLabel("ITERATIONS ", self.setup_widget)
        self.iterations_label.setGeometry(QtCore.QRect(0, 0, 200, 25)) 

        self.quantity_iterations_label = QtGui.QLabel("Quantity of Iterations: ", self.setup_widget)
        self.quantity_iterations_label.setGeometry(QtCore.QRect(25, 30, 200, 25)) 

        self.quantity_iterations_lineedit = QtGui.QLineEdit(self.setup_widget)
        self.quantity_iterations_lineedit.setGeometry(QtCore.QRect(175, 30, 100, 25))

        self.increment_points_label = QtGui.QLabel("Increment of Points: ", self.setup_widget)
        self.increment_points_label.setGeometry(QtCore.QRect(25, 60, 200, 25)) 

        self.increment_points_lineedit = QtGui.QLineEdit(self.setup_widget)
        self.increment_points_lineedit.setGeometry(QtCore.QRect(175, 60, 100, 25))

        self.points_region_label = QtGui.QLabel("Points Region: ", self.setup_widget)
        self.points_region_label.setGeometry(QtCore.QRect(25, 90, 200, 25))   
  
        self.region_combobox = QtGui.QComboBox(self.setup_widget)
        self.region_combobox.setGeometry(QtCore.QRect(175, 90, 65, 25))
        self.region_combobox.addItem("Space")        
        self.region_combobox.addItem("Disk")
        self.region_combobox.addItem("Circle")
        self.region_combobox.addItem("Triangle")
        self.region_combobox.addItem("Square")        
                
        self.algorithm_label = QtGui.QLabel("ALGORITHMS ", self.setup_widget)
        self.algorithm_label.setGeometry(QtCore.QRect(0, 130, 200, 25))        

        self.convexhull_label = QtGui.QLabel("Convex Hull: ", self.setup_widget)
        self.convexhull_label.setGeometry(QtCore.QRect(25, 160, 150, 25)) 

        self.algorithm_combobox = QtGui.QComboBox(self.setup_widget)
        self.algorithm_combobox.setGeometry(QtCore.QRect(175, 160, 100, 25))
        self.algorithm_combobox.addItem("Jarvis")
        self.algorithm_combobox.addItem("Scan")
        self.algorithm_combobox.setToolTip("Algorithm for convex hull problem")

        self.sorting_label = QtGui.QLabel("Sorting: ", self.setup_widget)
        self.sorting_label.setGeometry(QtCore.QRect(25, 190, 200, 25)) 

        self.sorting_combobox = QtGui.QComboBox(self.setup_widget)
        self.sorting_combobox.setGeometry(QtCore.QRect(175, 190, 100, 25))
        self.sorting_combobox.addItem("Merge")
        self.sorting_combobox.addItem("Quick")
        self.sorting_combobox.setToolTip("Algorithm for sorting numbers")

        self.configurations_label = QtGui.QLabel("CONFIGURATIONS ", self.setup_widget)
        self.configurations_label.setGeometry(QtCore.QRect(0, 230, 200, 25)) 

        self.remove_int_points_label = QtGui.QLabel("Remove Interior Points: ", self.setup_widget)
        self.remove_int_points_label.setGeometry(QtCore.QRect(25, 260, 150, 25)) 

        self.remove_int_points_checkbox = QtGui.QCheckBox(self.setup_widget)
        self.remove_int_points_checkbox.setGeometry(QtCore.QRect(175, 260, 20, 20)) 

        self.generate_graphics_label = QtGui.QLabel("Generate Graphics: ", self.setup_widget)
        self.generate_graphics_label.setGeometry(QtCore.QRect(25, 290, 200, 25)) 

        self.generate_graphics_checkbox = QtGui.QCheckBox(self.setup_widget)
        self.generate_graphics_checkbox.setGeometry(QtCore.QRect(175, 290, 20, 20)) 

        self.generate_images_label = QtGui.QLabel("Generate Images: ", self.setup_widget)
        self.generate_images_label.setGeometry(QtCore.QRect(25, 320, 200, 25)) 

        self.generate_images_checkbox = QtGui.QCheckBox(self.setup_widget)
        self.generate_images_checkbox.setGeometry(QtCore.QRect(175, 320, 20, 20)) 

        self.count_time_label = QtGui.QLabel("Count Time: ", self.setup_widget)
        self.count_time_label.setGeometry(QtCore.QRect(25, 350, 200, 25)) 

        self.count_time_checkbox = QtGui.QCheckBox(self.setup_widget)
        self.count_time_checkbox.setGeometry(QtCore.QRect(175, 350, 20, 20)) 

        self.buttons_widget = QtGui.QWidget(self.widget)
        self.buttons_widget.setGeometry(QtCore.QRect(5, 390, 550, 40))

        self.clear_buttom = QtGui.QPushButton("Clear", self.buttons_widget)
        self.clear_buttom.setGeometry(QtCore.QRect(25, 0, 100, 30))
        self.connect(self.clear_buttom, QtCore.SIGNAL("clicked()"), self.clear)

        self.add_process_buttom = QtGui.QPushButton("Add in Process", self.buttons_widget)
        self.add_process_buttom.setGeometry(QtCore.QRect(150, 0, 100, 30))
        self.connect(self.add_process_buttom, QtCore.SIGNAL("clicked()"), self.addProcess)

        self.cancel_buttom = QtGui.QPushButton("Cancel", self.buttons_widget)
        self.cancel_buttom.setGeometry(QtCore.QRect(275, 0, 100, 30))
        self.connect(self.clear_buttom, QtCore.SIGNAL("clicked()"), self.cancel)

        self.ok_buttom = QtGui.QPushButton("Ok", self.buttons_widget)
        self.ok_buttom.setGeometry(QtCore.QRect(400, 0, 100, 30))
        self.connect(self.add_process_buttom, QtCore.SIGNAL("clicked()"), self.ok)

        self.browser = QtGui.QTextBrowser(self.widget)
        self.browser.setGeometry(QtCore.QRect(300, 10, 250, 370))

    def addProcess(self):
        pass        

    def clear(self):
        pass
        
    def cancel(self):
        pass
        
    def ok(self):
        pass        
